﻿using System;
using System.Web.Mvc;
using PermissionManager.BLL;
using PermissionManager.Model;
using PermissionManager.Models;

namespace PermissionManager.Attributes
{
    /// <summary>
    /// 继承ActionFilterAttribute实现LogFilter日志
    /// </summary>
    public class LogFilter: ActionFilterAttribute
    {

        public LogFilter()
        {
        }

        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {

            if (filterContext == null)
            {
                throw new ArgumentNullException(nameof(filterContext));
            }

            object[] attrs = filterContext.ActionDescriptor.GetCustomAttributes(typeof(DescribeAttribute), false);
            if (attrs.Length > 0)
            {
                LogsService service=new LogsService();
                Logs logs = new Logs();
                logs.Content = ((DescribeAttribute)attrs[0]).FunDescribe;
                logs.AdminUserId =AdminUserContext.context.UserInfo_no.Id;               
                logs.CreateTime = DateTime.Now;
                logs.JName = AdminUserContext.context.UserInfo_no.Name; 
                service.Add(logs);

            }
            base.OnActionExecuted(filterContext);
        }
    }
}